package com.client.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.FieldPosition;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.JTextField;

import com.client.CommandSender;
import com.sendables.ChatMessage;

@SuppressWarnings("serial")
public class DoodleTextField extends JTextField implements ActionListener {
	private CommandSender	cs;
	private String			name;

	public DoodleTextField(CommandSender cs, String name)
	{
		this.name = name;
		this.cs = cs;
		addActionListener(this);
	}

	@Override
	public void actionPerformed(ActionEvent e)
	{
		if (getText().length() > 0)
		{
			Date d = new Date(System.currentTimeMillis());
			SimpleDateFormat sdf = new SimpleDateFormat("kk:mm");
			StringBuffer sb = new StringBuffer();
			sdf.format(d, sb, new FieldPosition(0));
			cs.postShape(new ChatMessage(name, sb.toString(), getText()));
			setText("");
		}
	}
}
